package com.ruoyi.unit.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.ruoyi.common.utils.StringUtils;
import java.util.List;
import java.util.Map;
import com.ruoyi.unit.mapper.BdUnitMapper;
import com.ruoyi.unit.domain.BdUnit;
import com.ruoyi.unit.service.IBdUnitService;

/**
 * 计量单位Service业务层处理
 *
 * @author ruoyi
 * @date 2023-11-14
 */
@Service
public class BdUnitServiceImpl extends ServiceImpl<BdUnitMapper, BdUnit> implements IBdUnitService {

    @Autowired
    private BdUnitMapper bdUnitMapper;

    /**
     * 查询计量单位列表
     *
     * @param bdUnit 计量单位
     * @return 计量单位
     */
    @Override
    public List<BdUnit> selectBdUnitList(BdUnit bdUnit)
    {
        List<BdUnit> bdUnitList = bdUnitMapper.selectList(buildQueryWrapper(bdUnit));
        return bdUnitList;
    }


    private LambdaQueryWrapper<BdUnit> buildQueryWrapper(BdUnit query) {
        Map<String, Object> params = query.getParams();
        LambdaQueryWrapper<BdUnit> lqw = Wrappers.lambdaQuery();
        lqw.like(StringUtils.isNotBlank(query.getName()), BdUnit::getName, query.getName());
        lqw.eq(StringUtils.isNotBlank(query.getNameEn()), BdUnit::getNameEn, query.getNameEn());
        lqw.orderByDesc(BdUnit::getCreateTime);
        return lqw;
    }

}
